import pygame, sys
import game
from pygame.locals import *	

def main():
	fpsClock = pygame.time.Clock()
	poll = 0
	pygame.init()
	pygame.time.set_timer(USEREVENT+1, 1)
	g = game.Game()
	g.screen.set_colorkey((255,0,255))
	time = 0
	while True:
		time = time + 1
		if time % 60 == 0:
			time = 0
		#print time
		g.update_time(time)
		for event in pygame.event.get():
			if (event.type == QUIT or g.check_quit() == True):
				pygame.quit()
				sys.exit()
			elif event.type == KEYDOWN:
				if event.key == K_ESCAPE:
					pygame.event.post(pygame.event.Event(QUIT))
			elif event.type == MOUSEBUTTONUP:
				if event.button == 1:
					g.poll = 1
			else:
				g.poll = 0
				
		g.screen.fill((0,0,0))
		if g.mode ==  0:
			g.main_menu.del_surfaces()
			g.screen.blit(g.main_menu.draw(g.level_status),(0,0))
			g.manage_menu(g.poll)
		elif g.mode == 2:
			g.selection_menu.del_surfaces()
			g.screen.blit(g.selection_menu.draw(g.level_status),(0,0))
			g.manage_menu(g.poll)
		elif g.mode == 1:
			g.screen.blit(g.draw_game(),(0,0))
			
		pygame.display.flip()
		fpsClock.tick(30)
		poll = 0 
		
main()